<?php
/**
 * @author Minh Luan
 * @copyright 2013 HCMC University of Science
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
 
GLOBAL $CFG;
define("ONE_WEEK", 7 * 24 * 60 * 60);
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/local/itusurveyplugin/lib.php');
//import jquery library
echo '<script src="../js/jquery-1.8.3.min.js"></script>';
echo '<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>';
//==================load stylesheet========================
$cssdir =  $CFG->wwwroot.'/local/itusurveyplugin/css/stylesheet.css';
echo '<link rel="stylesheet" href="'.$cssdir.'" type="text/css"/>';
//css for jquery GUI
echo "<link rel='stylesheet' href='http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css' type='text/css'/>";
//==================end stylesheet=================

//==================load module.js========================
//import module.js -> functions to get data via ajax
echo  '<script src="../module.js"></script>';
//==================end load js=================

//==================load itusurveylibrary.js========================
//defined specific functions for DOM Elements in pages
echo  '<script src="../js/itusurveylibrary.js"></script>';
//==================end load js=================

//*************************************************************************************************
//*					FORMS QUẢN LÝ QUESTION BEGIN		
//*************************************************************************************************
/**
 * Định nghĩa Form cho trang...................................................
 */ 
 class form_question_management extends moodleform{

	/**
	 * form_question_management::definition()
	 * 
	 * @return
	 */
	public function definition() {
        global $DB;
		$mform = &$this->_form;
        
        $mform->addElement('html','<div class="headingblock header"><a href="./add_question.php">'.get_string('QuestionMgtHeader','local_itusurveyplugin').'</a></div>');
       	
        //Search ITU Survey Question
		$mform->addElement('header', 'searchQuestionPanel', get_string('search','local_itusurveyplugin'), 'modulename');
        $mform->addElement('text', 'txtKeyword', get_string('keyword','local_itusurveyplugin'), $attributes='size="40"');
       
        //Load Type
        $optionsP = array('0'=>'- '.get_string('selectTypeQuestion','local_itusurveyplugin').' -');
        $questions = $DB->get_records_sql('SELECT * FROM mdl_itu_question_types', array());
        foreach($questions as $question) {
			//parent option
			$optionsP[$question->id] = $question->qt_content;
		}
        $mform->addElement('select', 'qt_type', get_string('question','local_itusurveyplugin'), $optionsP, null);
	   
        //Load Survey
        $optionsM = array('0'=>'- '.get_string('selectStatus','local_itusurveyplugin').' -',
                            '1'=>''.get_string('Used','local_itusurveyplugin').'',
                            '2'=> ''.get_string('NoUsed','local_itusurveyplugin').''
                            );
       
        $mform->addElement('select', 'qt_status', get_string('status','local_itusurveyplugin'), $optionsM, null);
        
         //Search Submit
         $mform->addElement('html','<div align="center">');
        $buttonarray=array();
        $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('search','local_itusurveyplugin'));
         $buttonarray[] =& $mform->createElement('cancel', 'cancel', get_string('cancel'));
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
        $mform->addElement('html','</div>');
        //$mform->addElement('button', 'searchQt', get_string('search','local_itusurveyplugin'), 
//                             $attributes='onclick="search_question_by_keyword($(\'#id_txtKeyword\').val());"');        
//		$mform->closeHeaderBefore('searchBtn');        
//		$mform->closeHeaderBefore('searchQt');
//        
//		$mform->addElement('html','<div id="questionList"></div>');
//        
//         //Preload all survey without criteria
//        $mform->addElement('html','<script>search_question_by_keyword("");</script>');
        //echo "<script>alert('Ok')</script>";
       }
}
class form_add_question extends moodleform{

	/**
	 * form_add_question::definition()
	 * 
	 * @return
	 */
	public function definition() {
        global $DB;
        global $USER; 
        global $SESSION;
		$mform = &$this->_form;
        
        $curLang = $SESSION->lang;
        $mform->addElement('html','<div class="headingblock header"><a>'.get_string('addQuestionheader','local_itusurveyplugin').'</a></div>');
        
        //Creator
        $mform->addElement('hidden', 'question_creator_id', $USER->id);
        
        //Load Type
        $optionsP = array('0'=>'- '.get_string('selectTypeQuestion','local_itusurveyplugin').' -');
        $questions = $DB->get_records_sql('SELECT * FROM mdl_itu_question_types', array());
        foreach($questions as $question) {
			//parent option
			$optionsP[$question->id] = $question->qt_content;
		}
        $mform->addElement('select', 'qt_type', get_string('TypeQuestion','local_itusurveyplugin'), $optionsP, array('onChange'=>'showTypeofQuestion(this.options[this.selectedIndex].value);'));
//        
        //Plain Text form
        $mform->addElement('html','<div id="plainText" style="display: none;">');
        
        $mform->addElement('textarea', 'plaintext_qt', get_string("question", "local_itusurveyplugin"),$attributes="wrap='virtual', rows='4', cols='80', onfocus='onfocus_checknull(\"pt\");', onblur='onblur_checknull(\"pt\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="plaintextwarning" style="margin-left:18%;color:red;" ></div>');
        
//        //Created Date
//        $mform->addElement('date_time_selector', 'createdDateTime', get_string('createdDate','local_itusurveyplugin'));
        $mform->addElement('html','</div>');
//        
//
//        
        //Dropdown List form
        $mform->addElement('html','<div id="dropdownList" style="display: none;">');
                
        $mform->addElement('html','<table align=center style="margin-left:6.5%;">'); 
        $mform->addElement('html','<tr><td>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'dropdown_qt', get_string("question", "local_itusurveyplugin"),$attributes=" wrap='virtual', rows='4', cols='66', onfocus='onfocus_checknull(\"ddl\");', onblur='onblur_checknull(\"ddl\",\"".$curLang."\"); onblur_checknull(\"ddlans\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="ddlwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('text','dropdown_ans',get_string("answer","local_itusurveyplugin"),$attributes="style='width: 500px', onfocus='onfocus_checknull(\"ddlans\");', onblur='onblur_checknull(\"ddlans\",\"".$curLang."\"); onblur_checknull(\"ddl\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="addqtbuttonwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input id="addqtbutton" type="button" style="margin-left:16%; style="width:200px" value="'.get_string('addAnswer','local_itusurveyplugin').'" onclick=\'add_answer_down("ddl"); showaddquestionbutton();\' disabled/><br>');      
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');     
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td width="90%">');        
        $select = &$mform->addElement('select', 'selectdropdownanswer', '', array(), array('id'=>'select_ddl_answer','style'=>'width:500px','align'=>'left','onclick'=>'optiontext("ddl");'));
        $select->setMultiple(true);
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('up','local_itusurveyplugin').'" onclick=\'answer_up("ddl")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('delete','local_itusurveyplugin').'" onclick=\'answer_del("ddl")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('down','local_itusurveyplugin').'" onclick=\'answer_down("ddl")\'/>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'edit_ddl_option', '',$attributes=" wrap='virtual', rows='2', cols='66', onfocus=' onfocus_checknull(\"ddloption\");', onblur='onblur_checknull(\"ddloption\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="editoptionwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('button', 'editoptionbutton',get_string('editoptions','local_itusurveyplugin'),array('onclick'=>'edit_optiontext("ddl");'));
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');  
        
        $mform->addElement('text','ddl_temp','',array('style'=>'display: none;')); 
        $mform->addElement('html','</div>');
       
       
        //checkBox form
        $mform->addElement('html','<div id="checkBox" style="display: none;">');
        
        $mform->addElement('html','<table align=center style="margin-left:6.5%;">'); 
        $mform->addElement('html','<tr><td>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'checkbox_qt', get_string("question", "local_itusurveyplugin"), $attributes="wrap='virtual', rows='4', cols='66', onfocus='onfocus_checknull(\"cbx\");', onblur='onblur_checknull(\"cbx\",\"".$curLang."\"); onblur_checknull(\"cbxans\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="cbxwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('text','checkbox_ans',get_string("answer","local_itusurveyplugin"),$attributes="style='width: 500px', onfocus='onfocus_checknull(\"cbxans\");', onblur='onblur_checknull(\"cbxans\",\"".$curLang."\"); onblur_checknull(\"cbx\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="cbxanswarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input id="addcbxbutton" type="button" style="margin-left:16%; style="width:200px" value="'.get_string('addAnswer','local_itusurveyplugin').'" onclick=\'add_answer_down("cbx"); showaddquestionbutton();\'/><br>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>'); 
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td width="90%">');                     
        $select = &$mform->addElement('select', 'selectcheckboxnanswer', '', array(), array('id'=>'select_cbx_answer','style'=>'width:500px','align'=>'left','onclick'=>'optiontext("cbx");'));
        $select->setMultiple(true);
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('up','local_itusurveyplugin').'" onclick=\'answer_up("cbx")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('delete','local_itusurveyplugin').'" onclick=\'answer_del("cbx")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('down','local_itusurveyplugin').'" onclick=\'answer_down("cbx")\'/>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'edit_cbx_option', '',$attributes=" wrap='virtual', rows='2', cols='66', onfocus=' onfocus_checknull(\"cbxoption\");', onblur='onblur_checknull(\"cbxoption\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="editcbxoptionwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('button', 'editcbxoptionbutton',get_string('editoptions','local_itusurveyplugin'),array('onclick'=>'edit_optiontext("cbx");'));
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>'); 
        $mform->addElement('text','cbx_temp','',array('style'=>'display: none;')); 
        $mform->addElement('html','</div>');
        
          
        //Scale form
        $mform->addElement('html','<div id="Scale" style="display: none;">');
        
        $mform->addElement('textarea', 'scale_qt', get_string("question", "local_itusurveyplugin"), $attributes="wrap='virtual', rows='4', cols='65', onfocus='onfocus_checknull(\"scale\");', onblur='onblur_checknull(\"scale\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="scalewarning" style="margin-left:18%;color:red;" ></div>');
        
        $mform->addElement('html','<table align=center style="margin-left:4%;">'); 
        $mform->addElement('html','<tr><td>');
        $mform->addElement('html','<div>'.get_string('chooseyourscale','local_itusurveyplugin').'</div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td width ="50px"></td>');
        
        $mform->addElement('html','<td>');
        $mform->addElement('html','<div>'.get_string('from','local_itusurveyplugin').'</div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        
        $from_array = array();
        for($i=1;$i<=100;$i++)
        {
            $from_array[$i]= $i;
        }
        
        $mform->addElement('select','scale_ans_from','',$from_array);
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<div>'.get_string('to','local_itusurveyplugin').'</div>');
        $mform->addElement('html','</td>');
        //$mform->addElement('html','<td>');
         $mform->addElement('html','<td>');
         
        $to_array = array();
        for($i=1;$i<=100;$i++)
        {
            $to_array[$i]= $i;
        }
        $mform->addElement('select','scale_ans_to','',$to_array);
        $mform->addElement('html','</td>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');
        
        $mform->addElement('html','</div>');
        
        $mform->addElement('html','<div id="addquestionbutton" style="display: none;" align="center">');

        $buttonarray=array();
        $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('addQuestion','local_itusurveyplugin'));
         $buttonarray[] =& $mform->createElement('cancel', 'cancel', get_string('cancel'));
        $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
       
       $mform->addElement('html','</div>');
	   }
}
class form_itu_modify_question extends moodleform{

	/**
	 * form_itu_modify_question::definition()
	 * 
	 * @return
	 */
	public function definition() {
        global $DB;
        global $USER; 
        global $SESSION;
	$mform = &$this->_form;
        $curLang = $SESSION->lang;
        $id_qt = $this->_customdata['id'];
        $type_submit = $this->_customdata['type_submit'];
        //echo"<script>alert('".$type_submit."')</script>";
        if($type_submit == 'edit')
        $mform->addElement('html','<div class="headingblock header"><a>'.get_string('EditQuestionHeader','local_itusurveyplugin').'</a></div>');
        if($type_submit == 'clone')
        $mform->addElement('html','<div class="headingblock header"><a>'.get_string('CreateQuestion','local_itusurveyplugin').'</a></div>');
               //Creator
        $mform->addElement('hidden', 'question_creator_id', $USER->id);
        $mform->addElement('hidden', 'id_question', $id_qt);
        $mform->addElement('hidden', 'submit_type', $type_submit);
        // $subject = $DB->get_record('subject',array('id'=>$id));
        $type_qt = $DB->get_record('itu_questions',array('id'=>$id_qt));
        $type = $type_qt->q_question_type;
        
        //$mform->addElement('html','<div align ="center">'."Please Edit Your Question".'</div>');
        //$mform->addElement("html","<script>showTypeQuestion('".$type."');</script>");
        
        $question_type_content = $DB->get_record('itu_question_types',array('id'=>$type));
        
        $mform->addElement('select', 'qt_type', get_string('TypeQuestion','local_itusurveyplugin'), array(''.$question_type_content->qt_content.''));
        //Plain Text form
        if ($type != 1)
        $mform->addElement('html','<div id="plainText" style="display: none;">');
        
        $mform->addElement('textarea', 'plaintext_qt', get_string("question", "local_itusurveyplugin"),$attributes="wrap='virtual', rows='4', cols='65', onfocus='onfocus_checknull(\"pt\");', onblur='onblur_checknull(\"pt\",\"".$curLang."\");'");
        $mform->setDefault('plaintext_qt', ''.$type_qt->q_content.'');
        $mform->addElement('html','<div id="plaintextwarning" style="margin-left:18%;color:red;" ></div>');
        
        if ($type != 1)
        $mform->addElement('html','</div>');           
       
       //Dropdown list
        if($type != 2)
        $mform->addElement('html','<div id="dropdownList" style="display: none;">');
        
        $mform->addElement('html','<table align=center style="margin-left:6.9%;">'); 
        $mform->addElement('html','<tr><td>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'dropdown_qt', get_string("question", "local_itusurveyplugin"),$attributes=" wrap='virtual', rows='4', cols='65', onfocus='onfocus_checknull(\"ddl\");', onblur='onblur_checknull(\"ddl\",\"".$curLang."\"); onblur_checknull(\"ddlans\",\"".$curLang."\");'");
        $mform->setDefault('dropdown_qt', ''.$type_qt->q_content.'');
        $mform->addElement('html','<div id="ddlwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('text','dropdown_ans',get_string("answer","local_itusurveyplugin"),$attributes="style='width: 500px',onfocus='onfocus_checknull(\"ddlans\");', onblur='onblur_checknull(\"ddlans\",\"".$curLang."\"); onblur_checknull(\"ddl\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="addqtbuttonwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input id="addqtbutton" type="button" style="margin-left:16%; style="width:200px" value="'.get_string('addAnswer','local_itusurveyplugin').'" onclick=\'add_answer_down("ddl"); showaddquestionbutton();\' disabled/><br>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
  
        
        $dropdown_answer_array = $DB->get_records('ans_ddl_def', array('add_question'=>$id_qt));
        $ddl_answer = array();
        foreach($dropdown_answer_array as $dropdown_ans)
        {
            $ddl_answer[$dropdown_ans->add_content] = $dropdown_ans->add_content;
        }
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td width="90%">');                  
        $select = &$mform->addElement('select', 'selectdropdownanswer', '', $ddl_answer, array('id'=>'select_ddl_answer','style'=>'width:500px','align'=>'left','onmouseover'=>'setoptiontitle_automatic();','onclick'=>'optiontext("ddl");'));
        $select->setMultiple(true);
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('up','local_itusurveyplugin').'" onclick=\'answer_up("ddl")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('delete','local_itusurveyplugin').'" onclick=\'answer_del("ddl")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('down','local_itusurveyplugin').'" onclick=\'answer_down("ddl")\'/>');
        $mform->addElement('html','</td></tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'edit_ddl_option', '',$attributes=" wrap='virtual', rows='2', cols='66', onfocus=' onfocus_checknull(\"ddloption\");', onblur='onblur_checknull(\"ddloption\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="editoptionwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('button', 'editoptionbutton',get_string('editoptions','local_itusurveyplugin'),array('onclick'=>'edit_optiontext("ddl");'));
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');
        
        //Set value for text field
        $value_answer = array();
        foreach($dropdown_answer_array as $dropdown_ans)
        {
            $value_answer[$dropdown_ans->add_order] = '#'.$dropdown_ans->add_content.'#';
        }
       $ddl_string ='';
       $ddl_string = join($ddl_string, $value_answer);
       $mform->addElement('text','ddl_temp','', array('value'=>$ddl_string,'style'=>'display: none;'));
        
        if($type != 2)
        $mform->addElement('html','</div>');
        

       //Checkbox
        if($type != 3)
        $mform->addElement('html','<div id="checkBox" style="display: none;">');
        
        $mform->addElement('html','<table align=center style="margin-left:6.9%;">'); 
        $mform->addElement('html','<tr><td>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'checkbox_qt', get_string("question", "local_itusurveyplugin"), $attributes="wrap='virtual', rows='4', cols='65', onfocus='onfocus_checknull(\"cbx\");', onblur='onblur_checknull(\"cbx\",\"".$curLang."\"); onblur_checknull(\"cbxans\",\"".$curLang."\");'");
        $mform->setDefault('checkbox_qt', ''.$type_qt->q_content.'');
        $mform->addElement('html','<div id="cbxwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('text','checkbox_ans',get_string("answer","local_itusurveyplugin"),$attributes="style='width: 500px',onfocus='onfocus_checknull(\"cbxans\");', onblur='onblur_checknull(\"cbxans\",\"".$curLang."\"); onblur_checknull(\"cbx\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="cbxanswarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input id="addcbxbutton" type="button" style="margin-left:16%; style="width:200px" value="'.get_string('addAnswer','local_itusurveyplugin').'" onclick=\'add_answer_down("cbx"); showaddquestionbutton();\'/><br>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $checkbox_answer_array = $DB->get_records('ans_cbx_def', array('acd_question'=>$id_qt));
        $cbx_answer = array();
        foreach($checkbox_answer_array as $checkbox_ans)
        {
            $cbx_answer[$checkbox_ans->acd_content] = $checkbox_ans->acd_content;
        }
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td width="90%">');                   
        $select = &$mform->addElement('select', 'selectcheckboxnanswer', '', $cbx_answer, array('id'=>'select_cbx_answer','style'=>'width:500px','align'=>'left','onmouseover'=>'setoptiontitle_automatic();','onclick'=>'optiontext("cbx");'));
        $select->setMultiple(true);
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('up','local_itusurveyplugin').'" onclick=\'answer_up("cbx")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('delete','local_itusurveyplugin').'" onclick=\'answer_del("cbx")\'/><br>');
        $mform->addElement('html','<input type="button" style="width:55px" value="'.get_string('down','local_itusurveyplugin').'" onclick=\'answer_down("cbx")\'/>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        
        $mform->addElement('html','<tr>');
        $mform->addElement('html','<td>');
        $mform->addElement('textarea', 'edit_cbx_option', '',$attributes=" wrap='virtual', rows='2', cols='66', onfocus=' onfocus_checknull(\"cbxoption\");', onblur='onblur_checknull(\"cbxoption\",\"".$curLang."\");'");
        $mform->addElement('html','<div id="editcbxoptionwarning" style="margin-left:18%;color:red;" ></div>');
        $mform->addElement('button', 'editcbxoptionbutton',get_string('editoptions','local_itusurveyplugin'),array('onclick'=>'edit_optiontext("cbx");'));
        $mform->addElement('html','</td>');
        $mform->addElement('html','</tr>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');  
        
        //Set value for text field
        $value_answer = array();
        foreach($checkbox_answer_array as $checkbox_ans)
        {
            $value_answer[$checkbox_ans->acd_order] = '#'.$checkbox_ans->acd_content.'#';
        }
       $cbx_string ='';
       $cbx_string = join($cbx_string, $value_answer);
       
        $mform->addElement('text','cbx_temp','',array('value'=>$cbx_string,'style'=>'display: none;')); 
        
        if($type != 3)
        $mform->addElement('html','</div>');
        
       //Scale
       if($type != 4)     
       $mform->addElement('html','<div id="Scale" style="display: none;">');
        
        $mform->addElement('textarea', 'scale_qt', get_string("question", "local_itusurveyplugin"), $attributes="wrap='virtual', rows='4', cols='80', onfocus='onfocus_checknull(\"scale\");', onblur='onblur_checknull(\"scale\",\"".$curLang."\");'");
        $mform->setDefault('scale_qt', ''.$type_qt->q_content.'');
        $mform->addElement('html','<div id="scalewarning" style="margin-left:18%;color:red;" ></div>');
        
        
        $mform->addElement('html','<table align=center style="margin-left:4%;">'); 
        $mform->addElement('html','<tr><td>');
        $mform->addElement('html','<div>'.get_string('chooseyourscale','local_itusurveyplugin').'</div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td width ="50px"></td>');
        
        $mform->addElement('html','<td>');
        $mform->addElement('html','<div>'.get_string('from','local_itusurveyplugin').'</div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
       
        $temp;      
        $from_array = array();
        $scale_answer = $DB->get_record('ans_scale_def', array('asd_question'=>$id_qt));
       // if($type == 4){
        for($i=1;$i<=100;$i++)
        {
            $from_array[$i]= $i;
            if($from_array[$i]==$scale_answer->asd_lowbound)
            $temp = $i;
        }
       // }
        $mform->addElement('select','scale_ans_from','',$from_array);
        $mform->setDefault('scale_ans_from', ''.$from_array[$temp].'');
        
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
        $mform->addElement('html','<div>'.get_string('to','local_itusurveyplugin').'</div>');
        $mform->addElement('html','</td>');
        $mform->addElement('html','<td>');
       // $mform->addElement('html','<td>');
         
        $temp;      
        $to_array = array();
       // if($type == 4)
        for($i=1;$i<=100;$i++)
        {
            $to_array[$i]= $i;
            if($to_array[$i]==$scale_answer->asd_upbound)
            $temp = $i;
        }
        $mform->addElement('select','scale_ans_to','',$to_array);
        $mform->setDefault('scale_ans_to', $to_array[$temp]);
        $mform->addElement('html','</td>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');
        
        if($type != 4) 
        $mform->addElement('html','</div>');
       
       if($type_submit !='edit')
       $mform->addElement('html','<div id="addquestionbutton" align="center" style="display: none;" >');
       $mform->addElement('html','<div align="center">');
       $buttonarray=array();
       $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('EditQuestion','local_itusurveyplugin'));
       $buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('cancel'));
       $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
       $mform->addElement('html','</div>');
       if($type_submit !='edit')
       $mform->addElement('html','</div>');
       
       if($type_submit != 'clone')
       $mform->addElement('html','<div id="addquestionbutton" align="center" style="display: none;">');
       $mform->addElement('html','<div align="center">');
       $buttonarray=array();
       $buttonarray[] =& $mform->createElement('submit', 'submitbutton', get_string('CreateQuestion','local_itusurveyplugin'));
       $buttonarray[] =& $mform->createElement('cancel', 'cancel', get_string('cancel'));
       $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
       $mform->addElement('html','</div>');
       if($type_submit !='clone')
       $mform->addElement('html','</div>');
    }
}
//*************************************************************************************************
//*					FORMS QUẢN LÝ ITUSURVEY BEGIN
//*************************************************************************************************
/**
 * Định nghĩa Form cho trang surveymanagement.php
 */ 
 class form_survey_management extends moodleform{

	/**
	 * form_survey_management::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
        global $USER;
		$mform = &$this->_form;
		
        //Lay du lieu tu field
		//Sample: $bien = $this->_customdata['id field'];
        
        //User storage
        $mform->addElement('html', '<input type="hidden" id="user_id" name="user_id" value="'.$USER->id.'"/>');
        
		$mform->addElement('html','<div class="headingblock header"><a href="./add_survey.php">New ITU Survey</a></div>');
		
		//Search ITU Survey
		$mform->addElement('header', 'searchPanel', get_string('search','local_itusurveyplugin'), 'modulename');
        
        $mform->addElement('text', 'txtKeyword', get_string('keyword','local_itusurveyplugin'), $attributes='size="40"');
        
        //Load Program
        $optionsP = array('0'=>'- '.get_string('selectProgram','local_itusurveyplugin').' -');
        $programs = $DB->get_records_sql('SELECT * FROM mdl_program', array());
        foreach($programs as $program) {
			//parent option
			$optionsP[$program->id] = $program->program_name.' - Hệ '.$program->program_type;
		}
        //foreach($optionsP as $key => $value){
        //echo $key.'/'.$value.'<br/>';
        //}
        $mform->addElement('select', 'ddlProgram', get_string('program','local_itusurveyplugin'), $optionsP, null);
        
        //Load Major
        $optionsM = array('0'=>'- '.get_string('selectMajor','local_itusurveyplugin').' -');
        $majors = $DB->get_records_sql('SELECT * FROM mdl_major', array());
        foreach($majors as $major) {
			//parent option
			$optionsM[$major->id] = $major->major_name;
		}
        $mform->addElement('select', 'ddlMajor', get_string('major','local_itusurveyplugin'), $optionsM, null);
        
        //Button Submit
        $mform->addElement('button', 'searchBtn', get_string('search','local_itusurveyplugin'), 
                            $attributes='onclick="search_survey_by_program_and_major($(\'#id_txtKeyword\').val(), $(\'#id_ddlProgram\').val(), $(\'#id_ddlMajor\').val());"');        
		$mform->closeHeaderBefore('searchBtn');
        
		$mform->addElement('html','<div id="surveyList"></div>');
        
        //Preload all survey without crriteria
        $mform->addElement('html','<script>search_survey_by_program_and_major("",0,0);</script>');
	}
}

/**
 * Định nghĩa Form cho trang add_survey.php
 */ 
  class form_add_survey extends moodleform{

	/**
	 * form_add_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
        global $USER; 
		$mform = &$this->_form;
        
        //program id after select (used maintain data created by ajax after postback)
        //$selectedProgram = $this->_customdata['selectedProgram'];
        $mform->addElement('html','<div class="headingblock header"><a href="#" onclick="return false;">New ITU Survey</a></div>');
        
        //Title
        $mform->addElement('text', 'txtSurveyTitle', get_string('surveyTitle','local_itusurveyplugin'), $attributes='size="40"');
        $mform->addRule('txtSurveyTitle', get_string('required'), 'required', null, 'client', false, false);
        
        //Creator
        $mform->addElement('hidden', 'survey_creator_id', $USER->id);
        
        //Selected Majors storage
        $mform->addElement('html', '<input type="hidden" id="selected_major" name="selected_major" value=""/>');
        //Selected Questions storage
        $mform->addElement('html', '<input type="hidden" id="selected_question" name="selected_question" value=""/>');
        
        //Programs
        $optionsP = array('0'=>'- '.get_string('selectProgram','local_itusurveyplugin').' -');
        $programs = $DB->get_records_sql('SELECT * FROM mdl_program', array());
        foreach($programs as $program) {
			$optionsP[$program->id] = $program->program_name.' - Hệ '.$program->program_type;
		}
        $mform->addElement('select', 'ddlProgram', get_string('program','local_itusurveyplugin'), $optionsP, array('onChange'=>'showMajorsByProgram(this.options[this.selectedIndex].value);getMaxDepthLo(this.options[this.selectedIndex].value);'));
        $mform->addRule('ddlProgram', get_string('required'), 'nonzero', null, 'client', false, false);
        
        //Majors
        $mform->addElement('html','<table><tr><td width="160px" padding="50px" align="right">'.get_string('major','local_itusurveyplugin').'</td><td></td></tr>');
        $mform->addElement('html','<tr><td></td><td>');
        $mform->addElement('html','<div name="majorList" id="majorList" class="fitem fitem_fcheckbox"></div>');
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');
        
        //Depth LO
        $level = array('1'=>1,'2'=>2,'3'=>3,'4'=>4,'5'=>5,'6'=>6,'7'=>7);
        $mform->addElement('select', 'ddlDepthLo', get_string('selectLevelLo','local_itusurveyplugin'), $level, null);
        
        //ExpireDate
        $mform->addElement('date_time_selector', 'expireDateTime', get_string('expireDate','local_itusurveyplugin'));
        
        //Title of Summary Block
        $mform->addElement('text', 'txtTitleOfSummary', get_string('titleOfSummary','local_itusurveyplugin'), $attributes='size="80"');
        $mform->addRule('txtTitleOfSummary', get_string('required'), 'required', null, 'client', false, false);
        //Description of Summary Block
        $mform->addElement('editor', 'txtAreaSummary', get_string('descriptionSummary', 'local_itusurveyplugin'));
        $mform->setType('txtAreaSummary', PARAM_RAW);
        
        
        //Title of Question Block
        $mform->addElement('text', 'txtTitleOfQuestion', get_string('titleOfQuestion','local_itusurveyplugin'), $attributes='size="80"');
        $mform->addRule('txtTitleOfQuestion', get_string('required'), 'required', null, 'client', false, false);
        //Description of Question Block
        $mform->addElement('editor', 'txtAreaQuestion', get_string('descriptionQuestion', 'local_itusurveyplugin'));
        $mform->setType('txtAreaQuestion', PARAM_RAW);
        
        
        //Title of LO Block
        $mform->addElement('text', 'txtTitleOfLO', get_string('titleOfLO','local_itusurveyplugin'), $attributes='size="80"');
        $mform->addRule('txtTitleOfLO', get_string('required'), 'required', null, 'client', false, false);
        //Description of LO Block
        $mform->addElement('editor', 'txtAreaLO', get_string('descriptionLO', 'local_itusurveyplugin'));
        $mform->setType('txtAreaLO', PARAM_RAW);
        
        //ITUS Questions
        $questions = $DB->get_records('itu_questions');
        
        $mform->addElement('html', '<div id="tabs">');
            $mform->addElement('html', '<ul>');
                $mform->addElement('html', '<li><a href="#tabs-1">'.get_string('questionForITUS','local_itusurveyplugin').'</a></li>');
                $mform->addElement('html', '<li><a href="#tabs-2">'.get_string('selectedQuestions','local_itusurveyplugin').'</a></li>');
            $mform->addElement('html', '</ul>');
            $mform->addElement('html', '<div id="tabs-1">');
                $mform->addElement('html', '<ul id="sortable1" class="connectedSortable ui-helper-reset">');
                    foreach($questions as $aQuestion){
                        $mform->addElement('html', '<li class="ui-state-default" value="'.$aQuestion->id.'">'.$aQuestion->q_content.'</li>');    
                    }
                $mform->addElement('html', '</ul>');
            $mform->addElement('html', '</div>');
            $mform->addElement('html', '<div id="tabs-2">');
                $mform->addElement('html', '<ul id="sortable2" class="connectedSortable ui-helper-reset">');
                $mform->addElement('html', '</ul>');
           $mform->addElement('html', '</div>');
        $mform->addElement('html', '</div>');
        
        $buttonarray=array();
        //Preview Button
        $buttonarray[] =& $mform->createElement('button', 'previewBtn', get_string('previewSurvey','local_itusurveyplugin'), $attributes="onclick=preview_survey_before_add();");
        //Draft Button
        $buttonarray[] =& $mform->createElement('submit', 'draftBtn', get_string('draftSurvey','local_itusurveyplugin'), $attributes="onclick=\"getValueOfUnorderedList('selected_question','sortable2');getCheckboxValue('selected_major','majors');\"");
        //Publish Button
        $buttonarray[] =& $mform->createElement('submit', 'publishBtn', get_string('publishSurvey','local_itusurveyplugin'), $attributes="onclick=\"getValueOfUnorderedList('selected_question','sortable2');getCheckboxValue('selected_major','majors');\"");
        //$buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('cancel'));
        $mform->addElement('html','<table><tr><td width="160px" padding="50px" align="right"></td><td width="500px">');
        $mform->addGroup($buttonarray, 'btnArray', '', array(' '), false);
        $mform->addElement('html','</td></tr></table>');
        
        //Drageable Questions
        echo "<script>";
        echo '$(function() {
                    $( "#sortable1, #sortable2" ).sortable().disableSelection();
                    var $tabs = $( "#tabs" ).tabs();
                    var $tab_items = $( "ul:first li", $tabs ).droppable({
                        accept: ".connectedSortable li",
                        hoverClass: "ui-state-hover",
                        drop: function( event, ui ) {
                            var $item = $( this );
                            var $list = $( $item.find( "a" ).attr( "href" ) ).find( ".connectedSortable" );
                            ui.draggable.hide( "slow", function() {
                                $tabs.tabs( "select", $tab_items.index( $item ) );
                                $( this ).appendTo( $list ).show( "slow" );
                            });
                        }
                    });
                 });';
        echo "</script>";   
    }
}

/**
 * Định nghĩa Form cho trang edit_survey.php
 */ 
 class form_edit_survey extends moodleform{

	/**
	 * form_edit_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
        global $USER;
		$mform = &$this->_form;
        
        $survey_id = $this->_customdata['id'];
        $survey_infor = $DB->get_record("itu_survey", array("id"=>$survey_id));
        
        //Title
        $mform->addElement('text', 'txtSurveyTitle', get_string('surveyTitle','local_itusurveyplugin'), $attributes='size="40" value="'.$survey_infor->itus_title.'"');
        $mform->addRule('txtSurveyTitle', get_string('required'), 'required', null, 'client', false, false);
        
        //Creator
        $mform->addElement('hidden', 'survey_creator_id', $USER->id);
        
        //Survey Id storage
        $mform->addElement('html','<input type=hidden name=id value='.$survey_id. '>');
        //Selected Majors storage
        $mform->addElement('html', '<input type="hidden" id="selected_major" name="selected_major" value=""/>');
        //Selected Questions storage
        $mform->addElement('html', '<input type="hidden" id="selected_question" name="selected_question" value=""/>');
        
        //Programs
        //Get program list with ID and String Display
        $optionsP = array();
        $programs = $DB->get_records_sql('SELECT * FROM mdl_program', array());
        foreach($programs as $program) {
			$optionsP[$program->id] = $program->program_name.' - Hệ '.$program->program_type;
		}
        $ddlProgram = &$mform->addElement('select', 'ddlProgram', get_string('program','local_itusurveyplugin'), $optionsP, array('onChange'=>'showMajorsByProgram(this.options[this.selectedIndex].value);'));
        //Set selected program of survey
        $ddlProgram->setSelected($survey_infor->itus_program);
        $mform->addRule('ddlProgram', get_string('required'), 'nonzero', null, 'client', false, false);
        
        //Majors
        $majorOfProgram = $DB->get_records("major", array("program_id"=>$survey_infor->itus_program));
        
        $selectedMajor = $DB->get_records("surveyed_majors", array("sm_survey"=>$survey_id));
        $selectedMajorArray = array();
        foreach($selectedMajor as $aSelectedMajor){
            $selectedMajorArray[$aSelectedMajor->sm_major]=$aSelectedMajor->sm_name;
        }
        
        $mform->addElement('html','<table><tr><td width="160px" padding="50px" align="right">'.get_string('major','local_itusurveyplugin').'</td><td></td></tr>');
        $mform->addElement('html','<tr><td></td><td>');
        $mform->addElement('html','<div name="majorList" id="majorList" class="fitem fitem_fcheckbox">');
        //display major checkboxes BEGIN
        
        foreach($majorOfProgram as $aMajor){
            //check the selected majors
            if(array_key_exists($aMajor->id,$selectedMajorArray)){
                $mform->addElement('html','<input type="checkbox" id="majors" name="majors" checked="checked" value="'.$aMajor->id.'" onclick="getCheckboxValue(\'selected_major\',\'majors\')"> '.$aMajor->major_name.'</br>');
            }else{
                $mform->addElement('html','<input type="checkbox" id="majors" name="majors" value="'.$aMajor->id.'" onclick="getCheckboxValue(\'selected_major\',\'majors\')"> '.$aMajor->major_name.'</br>');
            }
        }
        //display major checkboxes END
        $mform->addElement('html','</div>');        
        $mform->addElement('html','</td></tr>');
        $mform->addElement('html','</table>');
        
        //Depth LO
        $curLev = $survey_infor->itus_depth_lo;
        $level = array('1'=>1,'2'=>2,'3'=>3,'4'=>4,'5'=>5,'6'=>6,'7'=>7);
        $ddlDepth = &$mform->addElement('select', 'ddlDepthLo', get_string('selectLevelLo','local_itusurveyplugin'), $level, null);
        $ddlDepth->setSelected($curLev);
        
        //ExpireDate
        $mform->addElement('date_time_selector', 'expireDateTime', get_string('expireDate','local_itusurveyplugin'));
        
        //Title of Summary Block
        $mform->addElement('text', 'txtTitleOfSummary', get_string('titleOfSummary','local_itusurveyplugin'), $attributes='size="80" value="'.$survey_infor->itus_summary_title.'"');
        $mform->addRule('txtTitleOfSummary', get_string('required'), 'required', null, 'client', false, false);
        //Description of Summary Block
        $mform->addElement('editor', 'txtAreaSummary', get_string('descriptionSummary', 'local_itusurveyplugin'))->setValue(array('text' => $survey_infor->itus_summary));
        $mform->setType('txtAreaSummary', PARAM_RAW);
        
        
        //Title of Question Block
        $mform->addElement('text', 'txtTitleOfQuestion', get_string('titleOfQuestion','local_itusurveyplugin'), $attributes='size="80" value="'.$survey_infor->itus_question_title.'"');
        $mform->addRule('txtTitleOfQuestion', get_string('required'), 'required', null, 'client', false, false);
        //Description of Question Block
        $mform->addElement('editor', 'txtAreaQuestion', get_string('descriptionQuestion', 'local_itusurveyplugin'))->setValue(array('text' => $survey_infor->itus_question_summary));
        $mform->setType('txtAreaQuestion', PARAM_RAW);
        
        
        //Title of LO Block
        $mform->addElement('text', 'txtTitleOfLO', get_string('titleOfLO','local_itusurveyplugin'), $attributes='size="80" value="'.$survey_infor->itus_lo_title.'"');
        $mform->addRule('txtTitleOfLO', get_string('required'), 'required', null, 'client', false, false);
        //Description of LO Block
        $mform->addElement('editor', 'txtAreaLO', get_string('descriptionLO', 'local_itusurveyplugin'))->setValue(array('text' => $survey_infor->itus_lo_summary));
        $mform->setType('txtAreaLO', PARAM_RAW);
        
        //ITUS Questions
        $strCondition = "";
        //Get Selected Questions
        $selectedQuestions = $DB->get_records_sql('SELECT * FROM mdl_itu_questions WHERE id IN (SELECT qi_question FROM mdl_question_itus WHERE qi_itus = ? order by qi_order)', array($survey_id));
        $numbSelectedQuestions = count($selectedQuestions);
        $count = 1;
        foreach($selectedQuestions as $aSelectedQuestion){
            if($count < $numbSelectedQuestions){
                $strCondition .= $aSelectedQuestion->id.",";    
            }else{
                $strCondition .= $aSelectedQuestion->id;
            }
            $count++;
        }
        //Get Other Questions (other questions not in selected list)
        if(count($selectedQuestions) > 0){
            $questions = $DB->get_records_sql("SELECT * FROM mdl_itu_questions WHERE id not in (".$strCondition.")");    
        }else{
            $questions = $DB->get_records_sql("SELECT * FROM mdl_itu_questions");
        }
        
        
        $mform->addElement('html', '<div id="tabs">');
            $mform->addElement('html', '<ul>');
                $mform->addElement('html', '<li><a href="#tabs-1">'.get_string('questionForITUS','local_itusurveyplugin').'</a></li>');
                $mform->addElement('html', '<li><a href="#tabs-2">'.get_string('selectedQuestions','local_itusurveyplugin').'</a></li>');
            $mform->addElement('html', '</ul>');
            $mform->addElement('html', '<div id="tabs-1">');
                $mform->addElement('html', '<ul id="sortable1" class="connectedSortable ui-helper-reset">');
                    foreach($questions as $aQuestion){
                        $mform->addElement('html', '<li class="ui-state-default" value="'.$aQuestion->id.'">'.$aQuestion->q_content.'</li>');    
                    }
                $mform->addElement('html', '</ul>');
            $mform->addElement('html', '</div>');
            $mform->addElement('html', '<div id="tabs-2">');
                $mform->addElement('html', '<ul id="sortable2" class="connectedSortable ui-helper-reset">');
                    foreach($selectedQuestions as $aSelectedQuestion){
                        $mform->addElement('html', '<li class="ui-state-default" value="'.$aSelectedQuestion->id.'">'.$aSelectedQuestion->q_content.'</li>');    
                    }
                $mform->addElement('html', '</ul>');
           $mform->addElement('html', '</div>');
        $mform->addElement('html', '</div>');
        
        //Define buttons
        $buttonarray=array();
        //Preview Button
        $buttonarray[] =& $mform->createElement('button', 'previewBtn', get_string('previewSurvey','local_itusurveyplugin'), $attributes="onclick=preview_survey_before_update();");
        //$buttonarray[] =& $mform->createElement('button', 'previewBtn', get_string('previewSurvey','local_itusurveyplugin'));
        //Draft Button
        $buttonarray[] =& $mform->createElement('submit', 'draftBtn', get_string('draftSurvey','local_itusurveyplugin'), $attributes="onclick=\"getValueOfUnorderedList('selected_question','sortable2');getCheckboxValue('selected_major','majors');\"");
        //Publish Button
        $buttonarray[] =& $mform->createElement('submit', 'publishBtn', get_string('publishSurvey','local_itusurveyplugin'), $attributes="onclick=\"getValueOfUnorderedList('selected_question','sortable2');getCheckboxValue('selected_major','majors');\"");
        $mform->addElement('html','<table><tr><td width="160px" padding="50px" align="right"></td><td width="500px">');
        $mform->addGroup($buttonarray, 'btnArray', '', array(' '), false);
        $mform->addElement('html','</td></tr></table>');
        
        //Drageable Questions and set value to datetimeselector
        echo "<script>";
        echo '$(function() {
                    $( "#sortable1, #sortable2" ).sortable().disableSelection();
                    var $tabs = $( "#tabs" ).tabs();
                    var $tab_items = $( "ul:first li", $tabs ).droppable({
                        accept: ".connectedSortable li",
                        hoverClass: "ui-state-hover",
                        drop: function( event, ui ) {
                            var $item = $( this );
                            var $list = $( $item.find( "a" ).attr( "href" ) ).find( ".connectedSortable" );
                            ui.draggable.hide( "slow", function() {
                                $tabs.tabs( "select", $tab_items.index( $item ) );
                                $( this ).appendTo( $list ).show( "slow" );
                            });
                        }
                    });
                 });';
        echo "</script>";   
        
    }
}

/**
 * Định nghĩa Form cho trang clone_survey.php
 */
 class form_clone_survey extends moodleform{

	/**
	 * form_clone_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
        global $USER;
		$mform = &$this->_form;
        
        $mform->addElement('html','<div class="headingblock header"><a href="./clone_survey.php">Clone ITU Survey</a></div>');
        //User storage
        $mform->addElement('html', '<input type="hidden" id="user_id" name="user_id" value="'.$USER->id.'"/>');
        //selected survey storage (used to submit form)
        $mform->addElement('html', '<input type="hidden" id="selected_survey" name="selected_survey" value=""/>');
        
        //Filter survey list
		$mform->addElement('header', 'searchPanel', get_string('search','local_itusurveyplugin'), 'modulename');
        
        $mform->addElement('text', 'txtKeyword', get_string('keyword','local_itusurveyplugin'), $attributes='size="40"');
        
        //Load Program
        $optionsP = array('0'=>'- '.get_string('selectProgram','local_itusurveyplugin').' -');
        $programs = $DB->get_records_sql('SELECT * FROM mdl_program', array());
        foreach($programs as $program) {
			//parent option
			$optionsP[$program->id] = $program->program_name.' - Hệ '.$program->program_type;
		}
        $mform->addElement('select', 'ddlProgram', get_string('program','local_itusurveyplugin'), $optionsP, null);
        //Load Major
        $optionsM = array('0'=>'- '.get_string('selectMajor','local_itusurveyplugin').' -');
        $majors = $DB->get_records_sql('SELECT * FROM mdl_major', array());
        foreach($majors as $major) {
			$optionsM[$major->id] = $major->major_name;
		}
        $mform->addElement('select', 'ddlMajor', get_string('major','local_itusurveyplugin'), $optionsM, null);
        
        //Button Submit
        $mform->addElement('button', 'filterBtn', get_string('search','local_itusurveyplugin'), 
                            $attributes='onclick="filter_survey_by_program_and_major($(\'#id_txtKeyword\').val(), $(\'#id_ddlProgram\').val(), $(\'#id_ddlMajor\').val());"');        
		$mform->closeHeaderBefore('filterBtn');
                
        //Display survey list to choose
		$mform->addElement('html','<div id="surveyList"></div>');
        //Preload all survey without crriteria
        $mform->addElement('html','<script>filter_survey_by_program_and_major("",0,0);</script>');
        
    }
}

/**
 * Định nghĩa Form cho trang preview_itus.php
 */
 class form_preview_survey extends moodleform{

	/**
	 * form_preview_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
		$mform = &$this->_form;
        
        
        
    }
}		
//*************************************************************************************************
//*					FORMS QUẢN LÝ ITUSURVEYFILLING BEGIN
//*************************************************************************************************
/**
 * Định nghĩa Form cho trang survey_notification.php
 */ 
class form_notification_survey extends moodleform{

	/**
	 * form_notification_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
        global $USER;
		$mform = &$this->_form;
        
        $mform->addElement('html','<div id="surveyList"></div>');
        //Selected Majors storage
        $mform->addElement('html', '<input type="hidden" id="user" name="user" value="'.$USER->id.'"/>');
        
        $mform->addElement('html','<script>display_surveys_of_teacher(\''.$USER->id.'\');</script>');
        
    }
}

/**
 * Định nghĩa Form cho trang dosurvey.php
 */ 
class form_do_survey extends moodleform{

	/**
	 * form_notification_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
		global $DB;
        global $USER;
		$mform = &$this->_form;
        
        $survey_id = $this->_customdata['itus'];
        $subject_id = $this->_customdata['sid'];
        
        //hidden field to submit again these survey_id and subject_id (finish and send survey button)
        $mform->addElement("html","<input type=\"hidden\" name=\"itus\" value=\"".$survey_id."\"/>");
        $mform->addElement("html","<input type=\"hidden\" name=\"sid\" value=\"".$subject_id."\"/>");
        
        $teacher_id = $USER->id;
        $sts_id = $DB->get_record("itus_teachers_subjects", array("sts_survey_id"=>$survey_id,"sts_teacher_id"=>$teacher_id,"sts_subject_id"=>$subject_id));

        //Update status of Combination -teacher-survey-subject to doing if it is not-opened
        $DB->update_record("itus_teachers_subjects",array("id"=>$sts_id->id,"sts_status"=>1));
        
        $subject_infor = $DB->get_record("surveyed_subjects", array("ss_survey"=>$survey_id,"ss_subject"=>$subject_id));
        $teachers = $DB->get_records_sql("select * from mdl_surveyed_teachers where st_survey = ? and st_subject = ?", array($survey_id, $subject_id));
        
        //$mform->addElement('html',$teacher_id);
        $survey_infor = $DB->get_record("itu_survey", array("id"=>$survey_id));
        
        $mform->addElement('html', "<input type=\"hidden\" name=\"sts_id\" id=\"sts_id\" value=\"".$sts_id->id."\" />");
  //      <div style="background-color:yellow;border:1px solid black;padding:10px;">
//<p>HTML background code is limited, CSS background code is much better!</p>
//</div>
        $mform->addElement('html','<div style="background-color:#DCDCDC;border:1px solid black;">');
        //$mform->addElement('html','<div id="surveyList"></div>');
        $mform->addElement('html', "<center><h1>".$survey_infor->itus_title."</h1></center>");
        
        //Summary
        $mform->addElement('html', "<div style=\"text-align:center;\" id=\"summary_block\">");
             $mform->addElement('html', "<div id=\"title_sum\"><h2>".$survey_infor->itus_summary_title."</h2></div>");
             $mform->addElement('html', "<div style=\"text-align:left;padding-left:120px;padding-right:120px;\" id=\"sum\">".$survey_infor->itus_summary."</div>");
        $mform->addElement('html', "</div>");
        
        $mform->addElement('html', "</div>");
        
        //Questions
        
        $mform->addElement('html', "<div style=\"text-align:center; cursor:hand;\" id=\"question_block\">");
        
            $mform->addElement('html', "<div id=\"title_question\"><h2>".$survey_infor->itus_question_title."</h2></div>");
            
            $mform->addElement('html', "<div style=\"cursor:hand;\" id=\"toggleLink\" onclick=\"$('#survey_question_block').toggle(); curState = $('#toggleLink').html(); if(curState == '".get_string('collapse','local_itusurveyplugin')."'){\$('#toggleLink').html('".get_string('expand','local_itusurveyplugin')."')}else{\$('#toggleLink').html('".get_string('collapse','local_itusurveyplugin')."')};\">".get_string('collapse','local_itusurveyplugin')."</div>");            
        $mform->addElement('html', "</div>");
        
        $mform->addElement('html', "<div id=\"survey_question_block\" style=\"text-align:left;padding-left:120px;padding-right:120px;\">");
            $mform->addElement('html', "<div id=\"question_sum\">".$survey_infor->itus_question_summary."<br/></div>");
        
            //subject name
            $mform->addElement('html', "<u>".get_string('surveyedSubject','local_itusurveyplugin')."</u><br/>");
            $mform->addElement('html', $subject_infor->ss_name_en."-".$subject_infor->ss_name_vn);
            
            //list of teacher
            $mform->addElement('html', "<br/><br/><u>".get_string('teacherList','local_itusurveyplugin')."</u><br/>");
            $surveyedTeacherStr = "";
            $teacherStr = "";
            
            $teacherStr .= "<ul>";
            $surveyedTeacherStr .= "<ul>";
            foreach($teachers as $teacher){
                if(!($teacher->st_teacher == $teacher_id)){
                    $teacherStr .= "<li>".$teacher->st_fullname."</li>";
                }else{
                    $surveyedTeacherStr .= "<li><strong>".$teacher->st_fullname."</strong></li>";
                }  
            }
            $teacherStr .= "</ul>";
            $surveyedTeacherStr .= "</ul>";
            $mform->addElement('html',$teacherStr);
            //surveyed teacher
            $mform->addElement('html',$surveyedTeacherStr);
            $mform->addElement('html',"<br/>");
            //danh sách câu hỏi
            //$mform->addElement('html', "<div id=\"questions_of_survey\" style=\"text-align:left;padding-left:120px;padding-right:120px;\">");
                $questions = $DB->get_records_sql("select ituq.id, ituq.q_content, qi.qi_order, qi.qi_itus, ituq.q_question_type
                                                    from mdl_itu_questions ituq, mdl_question_itus qi
                                                    where ituq.id = qi.qi_question and qi.qi_itus = ?
                                                    order by qi.qi_order
                                                  ", array($survey_id));
                                                  
                $questionData = array();
                $answers = array();
                foreach($questions as $question){
                    $questionData = $question;
                    $mform->addElement('html', "<strong>".$questionData->q_content."</strong><br/>");
                    
                    //answers
                    if($questionData->q_question_type == 1){
                        $mform->addElement('html', "<textarea style=\"width:100%\" onclick=\"$(this).css({'background-color':'white'});\" onblur=\"save_answer(".$sts_id->id.",".$questionData->id.",1);\" name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."\">");
                        $ansValue = $DB->get_record('ans_plain', array('ap_sts'=>$sts_id->id, 'ap_question'=>$questionData->id));
                        //$ansValue = $DB->get_record_sql("select * from ans_plain where ap_sts = $sts_id and ap_question = ".$questionData->id);
                        //echo  "sts:".$sts_id;
                        //echo  "ap_question:".$questionData->id;
                        //echo  "ans:".$ansValue->ap_value;
                        $mform->addElement('html', $ansValue->ap_value);
                        $mform->addElement('html', "</textarea><br/><br/>");
                    }
                    if($questionData->q_question_type == 2){
                        $answers = $DB->get_records_sql("select * from mdl_ans_ddl_def where add_question = ? order by add_order asc", array($questionData->id));
                        $ansValue = $DB->get_record("ans_ddl", array("ad_sts"=>$sts_id->id,"ad_question"=>$questionData->id));
                        //$ansValue = $DB->get_record_sql("select * from ans_ddl where ad_sts = $sts_id and ad_question = ".$questionData->id);
                        foreach($answers as $answer){
                            if($ansValue->ad_value == $answer->id){
                                $mform->addElement('html',  "<div id=\"div_1_question_".$questionData->id."_".$answer->id."\"><input name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."\" value=\"".$answer->id."\" type=\"radio\" onchange=\"save_answer(".$sts_id->id.",".$questionData->id.",2);\" checked=\"checked\"/>".$answer->add_content."</div>");
                                $mform->addElement('html', "<br/>");       
                            }else{
                                $mform->addElement('html',  "<div id=\"div_1_question_".$questionData->id."_".$answer->id."\"><input name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."\" value=\"".$answer->id."\" type=\"radio\" onchange=\"save_answer(".$sts_id->id.",".$questionData->id.",2);\" />".$answer->add_content."</div>");
                                $mform->addElement('html', "<br/>");   
                            }
                            
                        }
                        $mform->addElement('html', "<br/><br/>");    
                    }
                    if($questionData->q_question_type == 3){
                        $answers = $DB->get_records_sql("select * from mdl_ans_cbx_def where acd_question = ? order by acd_order asc", array($questionData->id));
                        $ansValues = null;
                        foreach($answers as $answer){
                            $ansValues = $DB->get_records("ans_cbx", array("ac_sts"=>$sts_id->id,"ac_question"=>$questionData->id,"ac_value"=>$answer->id));
                            if(count($ansValues) > 0){
                                $mform->addElement('html',  "<div id=\"div_3_question_".$questionData->id."_".$answer->id."\"><input name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."_".$answer->id."\" value=\"".$answer->id."\" type=\"checkbox\" onchange=\"save_answer_of_checkbox(".$sts_id->id.",".$questionData->id.",".$answer->id.");\" checked=\"checked\"/>".$answer->acd_content."</div>");
                                $mform->addElement('html', "<br/>");
                            }else{
                                $mform->addElement('html',  "<div id=\"div_3_question_".$questionData->id."_".$answer->id."\"><input name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."_".$answer->id."\" value=\"".$answer->id."\" type=\"checkbox\" onchange=\"save_answer_of_checkbox(".$sts_id->id.",".$questionData->id.",".$answer->id.");\" />".$answer->acd_content."</div>");
                                $mform->addElement('html', "<br/>");
                            }                            
                        }       
                        $mform->addElement('html', "<br/><br/>");
                    }
                    if($questionData->q_question_type == 4){
                        $answers = $DB->get_records_sql("select * from mdl_ans_scale_def where asd_question = ?", array($questionData->id));
                        $ansValue = $DB->get_record("ans_scale", array("as_sts"=>$sts_id->id,"as_question"=>$questionData->id));
                        foreach($answers as $answer){
                            $up = $answer->asd_upbound;
                            $down = $answer->asd_lowbound;
                            for($i = $down; $i <= $up; $i++){
                                if($ansValue->as_value == $i){
                                    $mform->addElement('html',  "<div style=\"float:left\" id=\"div_4_question_".$questionData->id."_".$i."\"><input type=\"radio\" value=\"".$i."\" onchange=\"save_answer(".$sts_id->id.",".$questionData->id.",4);\" name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."\" checked=\"checked\"/>".$i."</div>");    
                                }else{
                                    $mform->addElement('html',  "<div style=\"float:left\" id=\"div_4_question_".$questionData->id."_".$i."\"><input type=\"radio\" value=\"".$i."\" onchange=\"save_answer(".$sts_id->id.",".$questionData->id.",4);\" name=\"question_".$questionData->id."\" id=\"question_".$questionData->id."\"/>".$i."</div>");
                                }
                            }       
                        }
                        $mform->addElement('html', "<br/><br/>");       
                    }  
                }
            
        $mform->addElement('html', "</div>");
        
        $mform->addElement('html','<div style="background-color:#DCDCDC;border:1px solid black;">');
        
        //LOs
        $mylib = new survey_management();
        
        $mform->addElement('html', "<div style=\"text-align:center;\" id=\"lo_block\">");
            $mform->addElement('html', "<div id=\"title_lo_sum\"><h2>".$survey_infor->itus_lo_title."</h2></div>");
            $mform->addElement('html', "<div style=\"text-align:left;padding-left:120px;padding-right:120px;\" id=\"lo_sum\">");
            $mform->addElement('html', $survey_infor->itus_lo_summary);
            $mform->addElement('html', "</div>");
            $mform->addElement('html', "<div id=\"los_of_survey\" style=\"text-align:left;padding-left:120px;padding-right:120px;\">");
                    $mform->addElement('html', "<div style=\"width:60%; float:left; font-weight:bold;\">Tiêu đề chuẩn đầu ra</div><div style=\"width:11%; float:left; font-weight:bold;\">I/T/U</div><div style=\"width:29%; float:left; font-weight:bold;\">Hoạt động giảng dạy và đánh giá</div>");
                    //recursive process to display LOs
                        $outputStr = "";
                        $mylib->displayChildLoDownToLev($survey_id, '1', $survey_infor->itus_depth_lo, "0", $mylib, &$outputStr, $sts_id->id);
                        $mform->addElement('html', $outputStr);
            $mform->addElement('html', "</div>");
        $mform->addElement('html', "</div>");
        
        //Storage for LO ID of current input assessment method
        $mform->addElement('html', "<input type=\"hidden\" name=\"lo_id\" id=\"lo_id\"/>");
        $mform->addElement('html','<div style="clear:both;padding-left:120px;padding-right:120px;text-align:center">');
        $mform->addElement('html','</div>');
        $mform->addElement('html','</div>');
        
        $mform->addElement('html','<div align="center">');
        $buttonarray=array();
        //Draft Button
        $buttonarray[] =& $mform->createElement('button', 'draftBtn', get_string('temporarySave','local_itusurveyplugin'), $attributes="onclick=\"redirectTo('notification.php')\"");
        //Publish Button
        $buttonarray[] =& $mform->createElement('submit', 'publishBtn', get_string('submitSurvey','local_itusurveyplugin'));
        
        $mform->addGroup($buttonarray, 'btnArray', '', array(' '), false);
        $mform->addElement('html','</div>');
        
        
        
        //Jquery Modal Form 
        $mform->addElement('html', "<div id=\"dialog_form\" title=\"Assessment Method and Teaching Method\">");
        $mform->addElement('html', "<form>");
        $mform->addElement('html', "<textarea id=\"input_assessment\" rows=\"2\" cols=\"30\"></textarea>");
        $mform->addElement('html', "</form>");
        $mform->addElement('html', "</div>");
        
        //collapse all LOs not checked
        echo "<script>";
        echo "$(function() {";
        //Check all checkbox and show LOs div BEGIN
        echo "$(\"div[id*='child_lo_block_']\").hide();";
        echo "$(\"input:checked[name*='ituCheckbox_']\").each(function(index){";
        echo "$(this).parents(\"div[id*='child_lo_block_']\").each(function(index){";
        echo "$(this).show();";
        echo "});";
        //echo "console.log($(this).attr('name'));";
        echo "});";
        //Jquery Modal Script Display
        //Check all checkbox and show LOs div END
        echo  "$(\"#dialog_form\").dialog({";
        	echo "autoOpen: false,";
        	echo "height: 200,";
        	echo "width: 300,";
        	echo "modal: true,";
            echo "position: { my: \"left top\", at: \"left bottom\", of: window },";
        	echo "buttons: {";
        	echo "\"Save input\": function() {";	
      			//close, clear input area, save by ajax and display input value
                //set value to div
                echo "var divId = '#assessmentLO_block_'+$('#lo_id').val();";
                echo "var inputValue = $('#input_assessment').val();";
                echo "$(divId).html(inputValue);";
                //save by ajax
                echo "save_assessment_teaching_method_of_lo($('#sts_id').val(),$('#lo_id').val(),inputValue);";
                //clear
                echo "$('#input_assessment').val('');";	
                echo "$('#lo_id').val('');";
                echo "$( this ).dialog( \"close\" );";
        	echo "},";	
        	echo "Cancel: function() {";
               echo "$('#input_assessment').val('');";	
        	   echo "$('#lo_id').val('');";
               echo "$( this ).dialog( \"close\" );";		
        	echo "}";	
        	echo "},";
        	echo "close: function() {";
        	   //close, clear input area,
               echo "$('#input_assessment').val('');"; 
               echo "$('#lo_id').val('');";
               echo "$( this ).dialog( \"close\" );"; 
        	echo "}";
        echo "});";
        echo "});";
        echo "</script>";
        
    }    
    
}
//*************************************************************************************************
//*					FORMS QUẢN LÝ ITUSURVEYREPORT BEGIN
//*************************************************************************************************
/**
 * Định nghĩa Form cho trang surveystatistic.php..........................................
 */ 
class form_statistic_survey extends moodleform{

	/**
	 * form_statistic_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
        global $DB;
        global $USER; 
        global $SESSION;
		$mform = &$this->_form;
        
        $curLang = $SESSION->lang;
        $mform->addElement('html','<div class="headingblock header"><a>'.get_string('statisticHeader','local_itusurveyplugin').'</a></div>');
        
        //Creator
        $mform->addElement('hidden', 'question_creator_id', $USER->id);
        
        // Load current Survey
        $optionsS = array('0'=>'- '.get_string('selectSurvey','local_itusurveyplugin').' -');
        $surveys = $DB->get_records_sql('SELECT * FROM mdl_itu_survey', array());
        foreach($surveys as $survey) {
			//parent option
			$optionsS[$survey->id] = $survey->itus_title;
		}
        $mform->addElement('select', 'survey', get_string('survey','local_itusurveyplugin'), $optionsS, array('onChange'=>'showSurveyTable(this.options[this.selectedIndex].value), showSurveyTableByStatus(\'0\', this.options[this.selectedIndex].value)'));
        $mform->addElement('html','<div id="temp_survey_id" style="display:none">');
        $mform->addElement('text','id_survey','');
        $mform->addElement('html','</div>');
        
//$str_survey= $str_survey.'<div style="background-color:#DCDCDC;border:1px solid black;">';
        $mform->addElement('html','<div id="surveytable" style="display:none;background-color:#DCDCDC;border:1px solid black;"></div>');
        
        
        
        $mform->addElement('html','<div id="selectstatus" style="display:none">');
        $mform->addElement('html','<div style="background-color:#DCDCDC;border:1px solid black;"></br>');
        $optionsS = array('0'=>'- '.get_string('selectStatus','local_itusurveyplugin').' -',
                            '1'=>''.get_string('notdo','local_itusurveyplugin').'',
                            '2'=>''.get_string('doing','local_itusurveyplugin').'',
                            '3'=>''.get_string('did','local_itusurveyplugin').'', );
        $mform->addElement('select', 'status', get_string('status','local_itusurveyplugin'), $optionsS, array('onChange'=>'showSurveyTableByStatus(this.options[this.selectedIndex].value,$(\'#id_id_survey\').val());'));
        
        $mform->addElement('html','<div id="surveytablestatus" style="display:none"></div>');
        
        $mform->addElement('text','email_teacher','',array('style'=>'display:none'));
        $mform->addElement('text','subject_teacher','',array('style'=>'display:none'));
        $mform->addElement('html','<div id="emailmessage" style="display:none">');
        $mform->addElement('html','</div>');
        $mform->addElement('html','</div>');
        
        $mform->addElement('html','<div style="background-color:#DCDCDC;border:1px solid black;"></br>');
        
        $mform->addElement('html','<div align="center" ><b>'.get_string('emailpreparation','local_itusurveyplugin').'');
        
        $mform->addElement('html','</b></div>');
        //Title of Summary Block
        $mform->addElement('text', 'email_subject', get_string('email_subject','local_itusurveyplugin'), $attributes='size="80px" value="ITU Survey Notification"');
        //$mform->addRule('txtTitleOfSummary', get_string('required'), 'required', null, 'client', false, false);
        //Description of Summary Block
        $mform->addElement('editor', 'email_content', get_string('email_content', 'local_itusurveyplugin'))->setValue(array('text' => "You have an ITU Survey, please go to notification section to do the survey"));
		//$mform->setType('txtAreaSummary', PARAM_RAW);
        
        
        $mform->addElement('button','sendemail','Send Email',array('onclick'=>'showemail($(\'#id_id_survey\').val())'));
        $mform->addElement('html','</div>');
        //Preload all survey without crriteria
        $mform->addElement('html','<div id="emailteacher"></div>');
        $mform->addElement('html','</div>');
        $mform->addElement('html','<div id="initialsurveytable" style="display:none">');
        //$mform->addElement('html','<script>showSurveyTable("0");</script>');
        $mform->addElement('html','<script>showSurveyTableByStatus("0",$(\'#id_id_survey\').val());</script>');
        //echo "<script>alert($('#id_id_survey').val())</script>";
        $mform->addElement('html','</div>');

        
    }
}
//*************************************************************************************************
//*					FORMS VIEW BENCHMARK BEGIN
//*************************************************************************************************
/**
 * Định nghĩa Form cho trang benchmark.php.........................................
 */ 
class form_benchmark_survey extends moodleform{

	/**
	 * form_benchmark_survey::definition()
	 * 
	 * @return
	 */
	public function definition() {
	    global $DB;
        global $USER; 
        global $SESSION;
		$mform = &$this->_form;        
        //hidden field to submit again these survey_id and subject_id (finish and send survey button)
        //$mform->addElement("html","<input type=\"hidden\" name=\"itus\" value=\"".$survey_id."\"/>");
        
        
        $optionsS = array('0'=>'- '.get_string('selectSurvey','local_itusurveyplugin').' -');
        $surveys = $DB->get_records_sql('select * from mdl_itu_survey where itus_expire_date < now() and itus_publish_date is not null', array());
        foreach($surveys as $survey) {
			//parent option
			$optionsS[$survey->id] = $survey->itus_title;
		}
        
        $mform->addElement('select', 'survey', get_string('selectSurvey','local_itusurveyplugin'), $optionsS, array('onChange'=>'showSurveyBenchmark(this.options[this.selectedIndex].value);'));
     
        $mform->addElement('html',"<img name=\"loader\" id=\"loader\" src=\"../css/images/ajax-loader.gif\" style=\"display:none;\">");
        $mform->addElement('html',"<iframe style=\"display: none;\" width=\"100%\" height=\"600px\" id=\"surveyBenchmark\" name=\"surveyBenchmark\">Your browser does not support iframe</iframe>");
        //$mform->addElement('html',"<div id=\"surveyBenchmark\" name=\"surveyBenchmark\" style=\"width:100%;\">");
        //$mform->addElement('html',"</div>");
        $mform->addElement('text',"benckmarktext",'',array('style'=>'display:none'));
        $mform->addElement('button', 'printBenchmarkBtn', "Export To Excel", 
                            $attributes=array('onclick'=>"ExportToExcel()",'style'=>"display: none; width:400px"));
        
        $mform->addElement('html',"<div id='dialog_instructor' title='Instructors'>");
        $mform->addElement('html',"<p id='instructorNames'></p>");
        $mform->addElement('html',"</div>");
        $mform->addElement('html',"<script>intializeTooltip()</script>");
	}
}
?>